<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
	xmlns="http://www.w3.org/2000/svg"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:flo="http://florence.sourceforge.net"
	xmlns:svg="http://www.w3.org/2000/svg"
	xmlns:xlink="http://www.w3.org/1999/xlink">
	
	<xsl:include href="tools.xsl"/>

	<xsl:output version='1.0' method="xml" encoding='UTF-8'/>
	<xsl:template match="/">
		<xsl:text disable-output-escaping="yes">&lt;?xml-stylesheet type="text/css" href="./florence.css"?&gt;</xsl:text>
		<svg xmlns="http://www.w3.org/2000/svg">
			<title>Florence's keyboard style</title>
			<desc>Style generated by florence: http://florence.sourceforge.net</desc>
			<xsl:apply-templates/>
		</svg>
	</xsl:template>

	<xsl:template match="svg:svg">
		<symbol>
		<xsl:copy-of select="attribute::viewBox"/>
		<xsl:choose>
			<xsl:when test="name(..)='shape'">
				<xsl:attribute name="preserveAspectRatio">none</xsl:attribute>
				<xsl:attribute name="id">s_<xsl:value-of select="../flo:name"/></xsl:attribute>
				<xsl:copy-of select="descendant::*"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:if test="document('keymap.xml')">
					<xsl:variable name="name"><xsl:value-of select="../flo:name"/></xsl:variable>
					<xsl:choose>
						<xsl:when test="document('keymap.xml')/keymap/symbols/symbol[$name = .]/@id">
							<xsl:attribute name="id"><xsl:value-of select="document('keymap.xml')/keymap/symbols/symbol[$name = .]/@id"/></xsl:attribute>
						</xsl:when>
						<xsl:otherwise>
							<xsl:attribute name="id">t_<xsl:value-of select="../flo:type"/></xsl:attribute>
						</xsl:otherwise>
					</xsl:choose>
					<xsl:attribute name="preserveAspectRatio">xMidYMid</xsl:attribute>
					<xsl:attribute name="class">symbol</xsl:attribute>
					<xsl:copy-of select="descendant::*"/>
				</xsl:if>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:text>
</xsl:text>
		</symbol>
	</xsl:template>

	<xsl:template match="flo:shapes">
		<xsl:for-each select="flo:shape">
			<xsl:apply-templates select="svg:svg"/>
		</xsl:for-each>
	</xsl:template>

	<xsl:template match="flo:symbols">
		<xsl:for-each select="flo:symbol">
			<xsl:apply-templates select="svg:svg"/>
		</xsl:for-each>
	</xsl:template>

	<xsl:template match="flo:style">
		<defs>
			<xsl:apply-templates select="flo:shapes"/>
			<xsl:apply-templates select="flo:symbols"/>
		</defs>
	</xsl:template>

</xsl:stylesheet>

